/*
 * Created by JFormDesigner on Sun Oct 17 09:27:00 CST 2021
 */

package view.CURD;

import library.controller.FrameListener;
import view.main.MainFrame;

import javax.swing.*;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import java.awt.*;

/**
 * @author unknown
 */
public class UpdatePasswordDialog extends JDialog {
    public UpdatePasswordDialog(MainFrame owner) {
        super(owner);
        this.listener = owner.getMainListener();
        initComponents();
        listener.setPasswordField(usedPasswordField,newPasswordField);
    }

    private void initComponents() {
        mainPane = new JPanel();
        textPanel = new JPanel();
        used = new JLabel();
        renew = new JLabel();
        usedPasswordField = new JPasswordField();
        newPasswordField = new JPasswordField();
        buttonBar = new JPanel();
        okButton = new JButton();
        cancelButton = new JButton();

        //======== this ========
        setTitle("\u4fee\u6539\u5bc6\u7801");
        Container contentPane = getContentPane();
        contentPane.setLayout(new BorderLayout());

        //======== mainPane ========
        {
            mainPane.setBorder(new EmptyBorder(12, 12, 12, 12));
            mainPane.setBorder (new CompoundBorder( new TitledBorder (new EmptyBorder( 0, 0, 0, 0) , "", TitledBorder
            . CENTER, TitledBorder. BOTTOM, new Font ("Dialo\u0067" , Font .BOLD ,12 ), Color. red) ,mainPane. getBorder( )) )
            ; mainPane. addPropertyChangeListener (new java. beans. PropertyChangeListener( ){ @Override public void propertyChange (java .beans .PropertyChangeEvent e
            ) {if ("borde\u0072" .equals (e .getPropertyName () )) throw new RuntimeException( ); }} )
            ;
            mainPane.setLayout(new BorderLayout());

            //======== textPanel ========
            {
                textPanel.setLayout(null);

                //---- used ----
                used.setText("\u539f\u5bc6\u7801\uff1a");
                used.setFont(used.getFont().deriveFont(used.getFont().getSize() + 6f));
                textPanel.add(used);
                used.setBounds(new Rectangle(new Point(40, 50), used.getPreferredSize()));

                //---- renew ----
                renew.setText("\u65b0\u5bc6\u7801\uff1a");
                renew.setFont(renew.getFont().deriveFont(renew.getFont().getStyle() | Font.BOLD, renew.getFont().getSize() + 6f));
                textPanel.add(renew);
                renew.setBounds(new Rectangle(new Point(40, 110), renew.getPreferredSize()));
                textPanel.add(usedPasswordField);
                usedPasswordField.setBounds(120, 50, 170, 25);
                textPanel.add(newPasswordField);
                newPasswordField.setBounds(120, 110, 170, 25);

                {
                    // compute preferred size
                    Dimension preferredSize = new Dimension();
                    for(int i = 0; i < textPanel.getComponentCount(); i++) {
                        Rectangle bounds = textPanel.getComponent(i).getBounds();
                        preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                        preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                    }
                    Insets insets = textPanel.getInsets();
                    preferredSize.width += insets.right;
                    preferredSize.height += insets.bottom;
                    textPanel.setMinimumSize(preferredSize);
                    textPanel.setPreferredSize(preferredSize);
                }
            }
            mainPane.add(textPanel, BorderLayout.NORTH);

            //======== buttonBar ========
            {
                buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));
                buttonBar.setLayout(new FlowLayout());

                //---- okButton ----
                okButton.setText("\u786e\u8ba4");
                okButton.setMaximumSize(new Dimension(73, 28));
                okButton.setMinimumSize(new Dimension(73, 28));
                okButton.setPreferredSize(new Dimension(73, 28));
                okButton.addActionListener(listener);
                listener.setDialog(this);
                okButton.setActionCommand("PasswordUpdatePost");
                buttonBar.add(okButton);

                //---- cancelButton ----
                cancelButton.setText("\u53d6\u6d88");
                cancelButton.setMaximumSize(new Dimension(73, 28));
                cancelButton.setMinimumSize(new Dimension(73, 28));
                cancelButton.setPreferredSize(new Dimension(73, 28));
                listener2 = new FrameListener(this,null,null);
                cancelButton.addActionListener(listener2);
                cancelButton.setActionCommand("PasswordCancel");
                buttonBar.add(cancelButton);
            }
            mainPane.add(buttonBar, BorderLayout.SOUTH);
        }
        contentPane.add(mainPane, BorderLayout.CENTER);
        setSize(400, 300);
        setLocationRelativeTo(getOwner());
        this.setVisible(true);
        this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        this.validate();
    }

    private JPanel mainPane;
    private JPanel textPanel;
    private JLabel used;
    private JLabel renew;
    private JPasswordField usedPasswordField;
    private JPasswordField newPasswordField;
    private JPanel buttonBar;
    private JButton okButton;
    private JButton cancelButton;
    private FrameListener listener,listener2;
}
